/**
 * Created by ZFL on 2018/1/8.
 */
function appInit() {
    PageInit();
}
function PageInit() {
    checkLogistics();
}

//查看物流
var vm = new Vue({
    el:"#app",
    data:{
        logisticsData:{}
    },
    mounted:function () {
        this.$nextTick(function () {
            //初始化
            this.cartView();
        });
    },
    methods:{
        cartView:function () {
        }
    }
});

function checkLogistics() {
    $.ajaxHandler({
        model: function () {
            var obj = {};
            obj.orderSn = $.getPara("orderSn");
            return obj;
        },
        visibleTime: 0,
        approve: true,
        api:"yg_baijiaplatform/order/getLogistics",
        success: function (result) {
            if (result.code == 10000) {
                var data = result.data;
                if(data.logisticsSessage!= ''){
                    var logisticsSessage = JSON.parse(data.logisticsSessage);
                    var obj = {};
                    obj.company = logisticsSessage.company;//物流公司
                    obj.no = logisticsSessage.no;//物流单号
                    obj.goodImgPath = data.goodImgPath;
                    obj.status = '未签收';
                    if(data.isFinish == 1){
                        obj.status = '已签收'
                    }
                    obj.isFinish = data.isFinish;
                    var list = logisticsSessage.list.reverse();
                    for(var i =0; i<list.length; i++){
                        if(list[i].remark.toString().indexOf("已签收")>-1){
                            list[i].isRemark=true;
                        }else {
                            list[i].isRemark=false;
                        }
                    }
                    obj.listData=list;
                    vm.logisticsData = obj;
                }else {

                    //当未发货时的物流状态
                    var obj = {};
                    obj.goodImgPath = data.goodImgPath;
                    obj.status='运输中';
                    obj.company= data.com;//物流公司
                    obj.no = data.no;//物流单号
                    vm.logisticsData = obj;
                    console.log(vm.logisticsData)
                }

            }else if(result.code == 20152){
                YDUI.dialog.toast("未从聚合中获取到物流信息", 'error', function () {
                });
            }else if(result.code == 20802){
                YDUI.dialog.toast("暂无物流信息", 'error', function () {
                });
            }else if(result.code=20805){
                YDUI.dialog.toast(result.message,1000)
                var obj = {};
                obj.goodImgPath =$.getPara('goodImgPath');
                obj.status='无物流信息';
                obj.company= $.getPara('company');//物流公司
                obj.no =  $.getPara('no');//物流单号
                vm.logisticsData = obj;
                console.log(vm.logisticsData)
            }
            else {
                YDUI.dialog.toast(result.message, 'error', function () {
                });
            }
        }
    });
}

//返回上一页
function returnBack() {
    window.history.back();  //返回上一页
}